defs/util: Add functions to assign (compiler friendly) an int to a pointer and back.
authoroliskoli <oliskoli@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Thu, 21 Aug 2008 22:01:43 +0000 (22:01 +0000)
committeroliskoli <oliskoli@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Thu, 21 Aug 2008 22:01:43 +0000 (22:01 +0000)
gpsbabel/defs.h
gpsbabel/util.c

index 4f774cd8bd0370f8a9dddd2696138a8a19201fac..891d4cd9e982f6bdadf298a251da79ca908bf709 100644 (file)
@@ -951,6 +951,9 @@ typedef enum {
 char gb_getbit(const void *buf, const gbuint32 nr);
 void gb_setbit(void *buf, const gbuint32 nr);
 
+void *gb_int2ptr(const int i);
+int gb_ptr2int(const void *p);
+
 /*
  *  From parse.c
  */
index 175f42750439c8ee39a3d08686cd94eb63b7d47a..4fdd2bb7c522c4c310ee477f6bd4c643f4705c67 100644 (file)
@@ -1760,3 +1760,30 @@ char gb_getbit(const void *buf, const gbuint32 nr)
        return (bytes[nr / 8] & (1 << (nr % 8)));
        
 }
+
+/*
+ * gb_int2ptr: Needed, when sizeof(*void) != sizeof(int) ! compiler warning !
+ */
+void *gb_int2ptr(const int i)
+{
+       union {
+               void *p;
+               int i;
+       } x = { NULL };
+
+       x.i = i;
+       return x.p;
+}
+
+/*
+ * gb_ptr2int: Needed, when sizeof(*void) != sizeof(int) ! compiler warning !
+ */
+int gb_ptr2int(const void *p)
+{
+       union {
+               const void *p;
+               int i;
+       } x = { p };
+
+       return x.i;
+}